Conclusion: The Story Ends
So, in the city of programming languages, C++ is the strong, versatile warrior, capable of
bending the machine to your will, but demanding careful attention. Java is the disciplined
strategist, prioritizing safety, portability, and simplicity. Choosing between them depends
on the mission: speed and control, or portability and ease of use?
By understanding these features, a programmer can navigate this city effectively, picking
the right language for the right purpose. And for an examiner reading this answer, it’s not
just a comparison; it’s a journey through the minds of two iconic programming languages.
2. What is Immutable String? How can you tokenize a given string? Which are various
methods of String Tokenizer Class?
Ans: Immutable Strings and String Tokenization in Java
A Different Beginning
Imagine you’ve written your name neatly on a whiteboard. Now, your mischievous friend
comes along and tries to change a letter. Instead of erasing your name, the teacher says:
“No, you can’t change what’s already written. If you want a new name, write it on a fresh
whiteboard.”
This is exactly how Strings in Java behave—they are immutable. Once created, they cannot
be changed. If you try to modify them, Java quietly creates a new string instead.
Now, suppose you’ve written a long sentence on that whiteboard: "Hello Rishabh, welcome
to Java programming."
If you want to split this sentence into smaller words—like “Hello”, “Rishabh”, “welcome”,
“to”, “Java”, “programming”—you need a way to tokenize it. That’s where String
Tokenization comes in.
What is an Immutable String?